﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace RadioThermostat.Common
{
    public class AsyncExecutor
    {
        public static void ExecuteTask(Action action, int timeoutMs)
        {
            EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
            AsyncCallback callback = ar => waitHandle.Set();
            action.BeginInvoke(callback, null);

            if (!waitHandle.WaitOne(timeoutMs))
                throw new Exception("Task timed out.");
        } 

    }
}
